package problems;

import java.util.HashSet;
import java.util.Set;

public class Euler052 extends AbstractEuler {

	@Override
	public Number calculate() {
		next_candidate:
		for (int i = 125874; i < Integer.MAX_VALUE; i++) {
			Set<Character> digits = makeSetOfCharacter(String.valueOf(i));
			for (int multiplier = 2; multiplier <= 6; multiplier++) {
				Set<Character> multipliedDigits = makeSetOfCharacter(String.valueOf(i * multiplier));
				if (!digits.equals(multipliedDigits)) continue next_candidate;
			}
			return i;
		}
		return null;
	}
	
	private Set<Character> makeSetOfCharacter(String string) {
		Set<Character> characters = new HashSet<Character>();
		for (Character character : string.toCharArray()) {
			characters.add(character);
		}
		return characters;
	}

	@Override
	protected Number getCorrectAnswer() {
		return 142857;
	}

}
